package com.mazihao.emos.service.impl;

import com.mazihao.emos.db.dao.MessageRefDao;
import com.mazihao.emos.db.dao.TbMessageDao;
import com.mazihao.emos.db.dao.TbMessageRefDao;
import com.mazihao.emos.db.pojo.TbMessage;
import com.mazihao.emos.db.pojo.TbMessageRef;
import com.mazihao.emos.service.MessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mazihao
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Resource
    private TbMessageDao tbMessageDao;

    @Resource
    private TbMessageRefDao tbMessageRefDao;

    @Override
    public void insertMessage(TbMessage message) {
        tbMessageDao.insert(message);
    }

    @Override
    public List<TbMessage> searchMessageByPage(int userId) {
        return tbMessageDao.searchMessageByPage(userId);
    }

    @Override
    public TbMessage searchMessageById(String id) {
        return tbMessageDao.searchMessageById(id);
    }

    @Override
    public TbMessageRef searchMessageRefByMessageId(String messageId, int userId) {
        return tbMessageRefDao.searchMessageRefByMessageId(messageId, userId);
    }

    @Override
    public void insertRef(TbMessageRef messageRef) {
        tbMessageRefDao.insert(messageRef);
    }

    @Override
    public long searchUnreadCount(int userId) {
        return tbMessageRefDao.searchUnreadCount(userId);
    }

    @Override
    public long searchLastCount(int userId) {
        return tbMessageRefDao.searchLastCount(userId);
    }

    @Override
    public long updateUnreadMessage(String id, int userId) {
        return tbMessageRefDao.updateUnreadMessage(id, userId);
    }

    @Override
    public long deleteMessageRefById(String id) {
        return tbMessageRefDao.deleteMessageRefById(id);
    }

    @Override
    public long deleteUserMessageRef(int userId) {
        return tbMessageRefDao.deleteUserMessageRef(userId);
    }
}
